local zuozheng = fk.CreateSkill {
  name = "lvshi__zuozheng",
}

Fk:loadTranslationTable{
  ["lvshi__zuozheng"] = "佐政",
  [":lvshi__zuozheng"] = "一名角色的弃牌阶段开始时，你可摸两张牌并交给其两张牌，然后其于此阶段改为将手牌弃置至每种花色各一张。",
  ["#lvshi__zuozheng-invoke"] = "佐政：你可以摸两张牌，交给%dest两张牌", 
  ["#lvshi__zuozheng-give"] = "佐政：请选择交给%dest的牌", 
  ["lvshi__zuozheng_throw"] = "佐政", 
  ["#lvshi__zuozheng"] = "佐政：请选择每种花色的牌各一张保留", 

  ["$lvshi__zuozheng_lvshi__zhangzhao"] = "君者当御贤于后，安可校勇于猛兽！",
  ["$lvshi__zuozheng_lsz__zhugejin"] = "后援即刻就到，诸将莫急！",
}

Fk:addPoxiMethod{
  name = "zuozheng",
  prompt = "#lvshi__zuozheng",
  card_filter = function (to_select, selected, data, extra_data)
    if data and #selected < #data then
      for _, id in ipairs(selected) do
        for _, v in ipairs(data) do
          if table.contains(v[2], id) and table.contains(v[2], to_select) then
            return false
          end
        end
      end
      return true
    end
  end,
  feasible = function(selected, data)
    return data and #data == #selected
  end,
  default_choice = function(data)
    if not data then return {} end
    local cids = table.map(data, function(v) return v[2][1] end)
    return cids
  end,
}

zuozheng:addEffect(fk.EventPhaseStart, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(zuozheng.name) and target.phase == Player.Discard and not target.dead
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {
      skill_name = zuozheng.name,
      prompt = "#lvshi__zuozheng-invoke::"..target.id,
    }) then
      event:setCostData(self, {tos = {target}})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.phase_end = true
    player:drawCards(2, zuozheng.name)
    if player:isNude() then return end
    if player ~= target then
      local cards = room:askToCards(player, {
        skill_name = zuozheng.name,
        include_equip = true,
        min_num = 2,
        max_num = 2,
        prompt = "#lvshi__zuozheng-give::"..target.id,
        cancelable = false,
      })
      room:moveCardTo(cards, Player.Hand, target, fk.ReasonGive, zuozheng.name, nil, false, player)
    end
    local card_data = {}
    local suits = {"spade", "heart", "club", "diamond"}
    for _, s in ipairs(suits) do
      local cards = table.filter(target:getCardIds("h"), function (id) return Fk:getCardById(id):getSuitString() == s end)
      if #cards > 0 then
        table.insert(card_data, {s, cards})
      end
    end
    if #card_data == 0 then return {} end
    local ret = room:askToPoxi(target, {
      poxi_type = "zuozheng",
      data = card_data,
      cancelable = false})
      local discards = table.filter(target:getCardIds("h"), function(id)
        return not table.contains(ret, id)
      end)
      room:throwCard(discards, zuozheng.name, target, target)
  end,
})


return zuozheng
